package guid

import (
	"context"

	"github.com/mars/internal/pkg/utils"
)

// WorkIdHolder定义workId生产jiek
type WorkIdHolder interface {
	WorkId(ctx context.Context) (int, error)
}

type WorkIdHolderFunc func(context.Context) (int, error)

func (fn WorkIdHolderFunc) WorkId(ctx context.Context) (int, error) {
	return fn(ctx)
}

var IpWorkHolder WorkIdHolderFunc = func(ctx context.Context) (workId int, err error) {
	ip, err := utils.PrivateIPV4()
	if err != nil {
		return
	}

	return int(ip[0]) ^ int(ip[1]) ^ int(ip[2]) ^ int(ip[3]), nil
}
